package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrCalcFeeUtil;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.SimCardMerchantAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 卡商属性联动处理类 field_name:200004040
 */
@Service
@AttrHandler(SimCardMerchantAttrHandler.class)
public class SimCardMerchantAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        //SIM卡类型
        KiteAttr simCardTypeAttr = inst.getAttr("200003678");
        if (KiteStringUtils.equalsAny(simCardTypeAttr.getValue(), "100007000", "100007001")) {
            //卡号数据服务费
            KiteAttr cardFeeAttr = inst.getAttr("200003679");
            if (Objects.nonNull(cardFeeAttr)) {
                double eSimCardFeeDoubleValue = LocalAttrCalcFeeUtil.calcESimCardFee(inst);
                String eSimCardFee = String.valueOf(eSimCardFeeDoubleValue);
                if ("0.0".equals(eSimCardFee)) {
                    cardFeeAttr.setValue("0");
                    cardFeeAttr.setValueDesc("0");
                }
                else {
                    cardFeeAttr.setValue(eSimCardFee);
                    cardFeeAttr.setValueDesc(eSimCardFee);
                }
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
